<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
    //数组绝对去重版本        包括数组和对象
        Array.prototype.uniq = function () {
            var hasNaN = false;
            var arr = [];
            for (var i = 0; i < this.length; i++) {
                //NaN
                if ( this[i]!==this[i] ){
                    if (hasNaN) {
                        this.splice(i, 1);
                        i--;
                    } else {
                        hasNaN = true;
                    }
                    continue;
                }
                //引用类型
                if (typeof this[i] === 'object') {
                    if (this[i] !== null) {
                        if (inArr(arr, this[i])) {
                            this.splice(i, 1);
                            i--;
                        } else {
                            arr.push(this[i]);
                        }
                        continue;
                    }
                }
                //普通类型
                if (this.indexOf(this[i]) !== this.lastIndexOf(this[i])) {
                    this.splice(i, 1);
                    i--;
                }
            }

            function inArr(arr, obj) {
                //空对象
                if (isEmpty(obj)) {
                    if (hasEmpty(arr)) {
                        return true;
                    } else {
                        return false;
                    }
                }
                //判断是否为一个空对象
                function isEmpty(obj) {
                    var flag = true;
                    for (var k in obj) {
                        flag = false;
                        break;
                    }
                    return flag;
                }
                //判断一个数组中是否有空对象
                function hasEmpty(arr) {
                    for (var i = 0; i < arr.length; i++) {
                        if (isEmpty(arr[i])) {
                            return true;
                        }
                    }
                }

                //非空对象
                var flag = false;
                for (var i = 0; i < arr.length; i++) {
                    if (flag) break;
                    for (var k in obj) {
                        if (arr[i][k] === obj[k]) {
                            flag = true;
                        } else {
                            flag = false;
                            break;
                        }
                    }
                }
                return flag;
            }
            return this;
        }

        var arr = [1, 1, '1', '1', 0, 0, true, false, true, false, null, null, {}, {},{name:'serioust'},{name:'serioust'},[],[],[1],[1], NaN, NaN];
        console.log(arr.uniq());
    </script>
</body>

</html>